// CommandLineHelper Library
// =========================
// License: Microsoft Permissive License (Ms-PL) v1.1
// Author: Rhy Mednick (http://www.rhyverse.net)
// Project Site: http://www.codeplex.com/CommandLineHelper
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using CommandLineHelper.Attributes;

namespace CommandLineHelper.Tests
{
    [TestFixture]
    public class ValidateSetAttribute_Test
    {
        /// <summary>
        ///Verify that the IgnoreCase property can be set and read properly.
        ///</summary>
        [Test]
        public void IgnoreCaseTest()
        {
            ValidateSetAttribute target = new ValidateSetAttribute();

            bool val = false;
            target.IgnoreCase = val;
            Assert.AreEqual(val, target.IgnoreCase, "CommandLineHelper.Attributes.ValidateSetAttribute.IgnoreCase was not set correctly.");

        }

        /// <summary>
        ///Verify validation function
        ///</summary>
        [Test]
        public void IsValid_ValidateSetAttribute()
        {
            ValidateSetAttribute target = new ValidateSetAttribute();
            target.ValidValues = new string[] { "This", "is", "a", "test", "list" };
            //verify an exact match
            object value = "test";
            bool expected = true;
            bool actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidateSetAttribute.IsValid did not return the expected value.");

            //verify no match with different case
            target.IgnoreCase = false;
            value = "tESt";
            expected = false;
            actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidateSetAttribute.IsValid did not return the expected value.");

            //verify match with different case
            target.IgnoreCase = true;
            value = "tESt";
            expected = true;
            actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidateSetAttribute.IsValid did not return the expected value.");


            //verify no match
            value = "nomatch";
            expected = false;
            actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidateSetAttribute.IsValid did not return the expected value.");
        }

        /// <summary>
        ///Verify that the property can be set and read properly.
        ///</summary>
        [Test]
        public void ValidValuesTest()
        {
            ValidateSetAttribute target = new ValidateSetAttribute();

            string[] val = { "This", "is", "a", "test" };
            target.ValidValues = val;
            CollectionAssert.AreEqual(val, target.ValidValues, "CommandLineHelper.Attributes.ValidateSetAttribute.ValidValues was not set correctly.");
        }
    }
}
